package com.zhang.use;

import com.zhang.step.AloneLog4j2;
import org.apache.logging.log4j.core.appender.AsyncAppender;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test35456711111 {


    //控制台appender~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    @Test
    public void test1() {
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        logger.trace("trace信息");
        logger.debug("debug信息");
        logger.info("info信息");
        logger.warn("warn信息");
        logger.error("error信息");

    }


    //文件appender~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //普通文件Appender
    @Test
    public void test2() {
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        logger.trace("trace信息");
        logger.debug("debug信息");
        logger.info("info信息");
        logger.warn("warn信息");
        logger.error("error信息");

    }

    //滚动文件Appender(基于时间进行拆分+基于大小进行拆分 + 基于时间and大小进行拆分)
    @Test
    public void test2_1() throws InterruptedException {
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        for (int i = 0; i < 50000; i++) {
            logger.trace("trace信息");
            logger.debug("debug信息");
            logger.info("info信息");
            logger.warn("warn信息");
            logger.error("error信息");

            Thread.sleep(1);
        }
    }


    //数据库appender~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    @Test
    public void test3() {


    }


    //异步日志~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //同步模式
    @Test
    public void test445() {
        //日志记录
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        for (int i = 0; i < 2000; i++) {
            logger.trace("trace信息");
            logger.debug("debug信息");
            logger.info("info信息");
            logger.warn("warn信息");
            logger.error("error信息");
        }

        //业务逻辑
        for (int i = 0; i < 1000; i++) {
            System.out.println("-----------------------" + i);
        }
    }

    //方式一: AsyncAppender
    @Test
    public void test4() {
        //日志记录
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        for (int i = 0; i < 2000; i++) {
            logger.trace("trace信息");
            logger.debug("debug信息");
            logger.info("info信息");
            logger.warn("warn信息");
            logger.error("error信息");
        }

        //业务逻辑
        for (int i = 0; i < 1000; i++) {
            System.out.println("-----------------------" + i);
        }
    }


    //方式二: AsyncLogger
    //(1)全局异步
    @Test
    public void test5() {
        //日志记录
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        for (int i = 0; i < 2000; i++) {
            logger.trace("trace信息");
            logger.debug("debug信息");
            logger.info("info信息");
            logger.warn("warn信息");
            logger.error("error信息");
        }

        //业务逻辑
        for (int i = 0; i < 1000; i++) {
            System.out.println("-----------------------" + i);
        }


    }

    //(2)混合异步
    @Test
    public void test6() {

        //日志记录
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        for (int i = 0; i < 2000; i++) {
            logger.trace("trace信息");
            logger.debug("debug信息");
            logger.info("info信息");
            logger.warn("warn信息");
            logger.error("error信息");
        }

        //业务逻辑
        for (int i = 0; i < 1000; i++) {
            System.out.println("-----------------------" + i);
        }

    }


    //过滤器研究~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    @Test
    public void test7() {
        //日志记录
        Logger logger = LoggerFactory.getLogger(AloneLog4j2.class);
        logger.trace("trace信息");
        logger.debug("debug信息");
        logger.info("info信息");
        logger.warn("warn信息");
        logger.error("error信息");
    }


}





















